<%= render partial: 'spree/admin/users/sidebar', locals: { current: :store_credits } %>

<% content_for :page_title do %>
  <%= link_to @user.email, spree.edit_admin_user_url(@user) %> /
  <%= Spree.t(:"admin.user.store_credits") %>
<% end %>

<% content_for :title do %>
  <%= "Spree #{Spree.t('administration')}: #{Spree.t(:"admin.user.store_credits")}" %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:add_store_credit), spree.new_admin_user_store_credit_path(@user), class: "btn-success", icon: 'add.svg' if can?(:create, Spree::StoreCredit) %>
<% end %>

<% if @store_credits.any? %>
<div class="table-responsive">
  <table class="table">
    <thead>
      <th><%= Spree.t(:credited) %></th>
      <th><%= Spree.t(:used) %></th>
      <th><%= Spree.t(:category) %></th>
      <th><%= Spree.t(:created_by) %></th>
      <th><%= Spree.t(:issued_on) %></th>
      <th data-hook="admin_store_credits_index_header_actions" class="actions"></th>
    <thead>
    <tbody>
      <% @store_credits.each do |store_credit| %>
        <tr>
          <td><%= store_credit.display_amount.to_html %></td>
          <td><%= store_credit.display_amount_used.to_html %></td>
          <td><%= store_credit.category_name %></td>
          <td><%= store_credit.created_by_email %></td>
          <td><%= l store_credit.created_at.to_date %></td>
          <td class="actions actions-2 text-center" data-hook="admin_store_credits_index_row_actions">
            <% if store_credit.amount_used.zero? %>
              <%= link_to_edit_url spree.edit_admin_user_store_credit_path(@user, store_credit), no_text: true if can?(:edit, store_credit) %>
              <%= link_to_delete store_credit, no_text: true, url: spree.admin_user_store_credit_path(@user, store_credit) if can?(:destroy, store_credit) %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::StoreCredit)) %>
  </div>
<% end %>

<%= render 'spree/admin/users/lifetime_stats' %>
